package com.fivefu.core.hillstone.controller;

import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
import com.fivefu.core.hillstone.services.DbHillstoneBusEquipmentGpsService;
import com.fivefu.core.hillstone.services.HillstoneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 大华_公交车基础信息 前端控制器
 * </p>
 *
 * @author 
 * @since 2022-11-07 16:56:50
 */
@Api(tags = "大华公交车")
@RestController
@RequestMapping("/db-hillstone-bus")
public class DbHillstoneBusController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(DbHillstoneBusController.class);

    @Autowired
    private DbHillstoneBusEquipmentGpsService dbHillstoneBusEquipmentGpsService;

    @Autowired
    private HillstoneService hillstoneService;

    @ApiOperation(value = "获取公交车监控视频",httpMethod = "POST",response = ResultInfo.class,notes = "获取公交车监控视频")
    @ApiImplicitParam(value = "设备编码", name = "deviceCode", dataType = "String")
    @RequestMapping(path = "/getBusMonitor",method = RequestMethod.POST)
    public ResultInfo getBusMonitor() {
        String deviceCode = request.getParameter("deviceCode");
        logger.info("获取公交车监控视频");
        try {
            //调用登录
            hillstoneService.login();
            List<Map> list = dbHillstoneBusEquipmentGpsService.surveillanceVideo(deviceCode);
            //销毁会话
            hillstoneService.destoryToken();
            return ResultInfo.renderSuccess(list);
        } catch (Exception e) {
            //销毁会话
            logger.error(e.getMessage(),e);
            return ResultInfo.renderError("获取公交车监控视频失败");
        }
    }

    @ApiOperation(value = "获取公交车设备信息",httpMethod = "POST",response = ResultInfo.class,notes = "获取公交车设备信息")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "车辆状态", name = "isOnline", dataType = "String"),
        @ApiImplicitParam(value = "设备名称", name = "deviceName", dataType = "String")
    })
    @RequestMapping(path = "/getBusData",method = RequestMethod.POST)
    public ResultInfo getBusData() {
        Map<String, String> params = formatDataToMap();
        String isOnline = params.get("isOnline");
        String deviceName = params.get("deviceName");
        logger.info("获取公交车设备信息");
        try {
            Map<String, List> map = dbHillstoneBusEquipmentGpsService.inquireBusData(deviceName, isOnline);
            return ResultInfo.renderSuccess(map);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            return ResultInfo.renderError("获取公交车设备信息");
        }
    }
}
